package com.lexin.action.controller.service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.lexin.action.model.UserAccounts;
import com.lexin.action.service.SignupService;
import com.lexin.common.base.BaseController;
import com.lexin.common.base.SystemProperties;
import com.lexin.common.utils.BeanUtil;


@Controller
@RequestMapping("/service/sas/")
public class SignupAndSignonSController extends BaseController {

	@Autowired
	SignupService signupService;
	
	@RequestMapping("/signup")
	public ModelAndView upload( HttpServletRequest request, HttpServletResponse response ) throws Exception {
		String message = null;
		UserAccounts userAccounts = (UserAccounts) BeanUtil.formBean(request, UserAccounts.class);
		int res = signupService.signup(userAccounts);
		if (res==-1) {
			message = "GET ID FAIL";
			throw new Exception(message);
		} else if (res==0) {
			message = "ACCOUNTS SIGNUP FAIL";
			throw new Exception(message);
		} else if (res==1) {
			message = "ACCOUNTS SIGNUP SUCCESS";
		}
		response.setCharacterEncoding(SystemProperties.ENCODING);
		response.getWriter().print( JSONObject.wrap(message) );
		return null;
	}
	
}
